//公用的函数
"use strict";
var vw_common = function() {
	return {
		ConLog: function(userName, operation) {
			//			$.ajax({
			//				url: VW_INTERFACE.WEBSERVICE.LoginManage("WriteLogin"),
			//				type: "POST",
			//				dataType: "json",
			//				data: {
			//					"userName": userName,
			//					"operation": operation
			//				}
			//			});
		},

		customAjax: function(para, successCallback, errorCallback, completeCallback) {
			if(!para.data) {
				para.data = {};
			}
			var fn = para.url.split('/');
			para.data.operation = fn[fn.length - 1];

			try {
				para.data.functionID = vw_static.getQueryString(window, "fid");

				if(!para.data.userName) {
					var uid = vw_static.getCookie(window.location.host);
					var uName = vw_static.getCookie(uid).split('|')[0];
					para.data.userName = uName;
				}
			} catch {
				para.data.functionID = "999";
				para.data.userName = "APP";
			}

			//			para.timeout = 3000;

			para.success = function(e) {
				if(e.success) {
					if(successCallback) {
						successCallback(e);
					}
				} else {
					if(errorCallback) {
						errorCallback();
					}
					$.Notify({
						caption: "错误",
						content: e.msg,
						type: "alert"
					});
					console.error(e.msg);
				}
			};

			para.error = function(err) {
				var msg = err.status + "(" + err.statusText + ")";
				if(errorCallback) {
					errorCallback(msg);
				}
				$.Notify({
					caption: "错误",
					content: msg,
					type: "alert"
				});
				console.error(msg);
			};

			para.beforeSend = function() {
				window.ajaxCount++;
			};

			para.complete = function() {
				if(completeCallback) {
					completeCallback();
				}

				window.ajaxCount--;

				if(window.ajaxCount == 0) {
					document.getElementById('loading').style.display = "none";
				}
			};
			$.ajax(para);
		},
	}
}();